cmake_minimum_required(VERSION 3.12)
project(WebSocketServer CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 编译器选项
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2")
endif()

# 包含目录
include_directories(include)

# 服务器可执行文件
add_executable(websocket_server
    src/server/main.cpp
    src/server/websocket_server.cpp
    src/common/websocket_frame.cpp
    src/common/utils.cpp
)

# 客户端可执行文件
add_executable(websocket_client
    src/client/main.cpp
    src/client/websocket_client.cpp
    src/common/websocket_frame.cpp
    src/common/utils.cpp
)

# 测试可执行文件
add_executable(websocket_tests
    tests/test_server.cpp
    src/common/websocket_frame.cpp
    src/common/utils.cpp
    src/server/websocket_server.cpp
    src/server/websocket_session.cpp
    src/client/websocket_client.cpp
)

# 查找必要的库
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)

# 链接库
target_link_libraries(websocket_server Threads::Threads OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(websocket_client Threads::Threads OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(websocket_tests Threads::Threads OpenSSL::SSL OpenSSL::Crypto)

# 安装目标
install(TARGETS websocket_server websocket_client
    RUNTIME DESTINATION bin
)